import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: '文学管理系统',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '文学管理系统', icon: 'dashboard' }
    }]
  },
  {
    path: '/cms/book',
    component: Layout,
    redirect: '/cms/book',
    name: 'Book', // ## 每个路由name不能相同
    meta: { title: '内容管理', icon: 'example' },
    alwaysShow: true,
    children: [
      {
        path: 'list',
        name: 'CmsBookList',
        component: () => import('@/views/cms/book/list'),
        meta: { title: '书籍列表', icon: 'table' }
      },
      {
        path: 'create',
        name: 'CmsBookCreate',
        component: () => import('@/views/cms/book/create'),
        meta: { title: '添加书籍', icon: 'form' },
        hidden: true
      },
      {
        path: 'update/:id', // ## :id 相当于占位符,要传参数
        name: 'CmsBookUpdate',
        component: () => import('@/views/cms/book/update'),
        meta: { title: '编辑书籍', noCache: true },
        hidden: true
      }
    ]
  },
  {
    path: '/copyrightin/copyrightin',
    component: Layout,
    redirect: '/bms/copyright',
    name: 'Copyright',
    meta: { title: '版权引进', icon: 'example' },
    alwaysShow: true,
    children: [
      {
        path: 'list',
        name: 'CopyrightinList',
        component: () => import('@/views/copyrightin/copyrightin/list'),
        meta: { title: '版权方管理', icon: 'table' }
      },
      {
        path: 'create',
        name: 'CopyrightinCopyrightinCreate',
        component: () => import('@/views/copyrightin/copyrightin/create'),
        meta: { title: '添加版权', icon: 'form' },
        hidden: true
      },
      {
        path: 'update/:id',
        name: 'CopyrightinCopyrightinUpdate',
        component: () => import('@/views/copyrightin/copyrightin/update'),
        meta: { title: '编辑版权', noCache: true },
        hidden: true
      },
      {
        path: 'ManList/:id',
        name: 'CopyrightinManList',
        component: () => import('@/views/copyrightin/copyrightin/ManList'),
        meta: { title: '版权方客户管理', icon: 'form' },
        hidden: true
      },
      {
        path: 'ManCreate',
        name: 'CopyrightinManCreate',
        component: () => import('@/views/copyrightin/copyrightin/ManCreate'),
        meta: { title: '添加客户', icon: 'form' },
        hidden: true
      },
      {
        path: 'updateMan/:id',
        name: 'CopyrightinManUpdate',
        component: () => import('@/views/copyrightin/copyrightin/ManUpdate'),
        meta: { title: '编辑客户信息', noCache: true },
        hidden: true
      }
    ]
  },
  {
    path: '/bms/copyright',
    component: Layout,
    redirect: '/bms/copyright',
    name: 'Copyright',
    meta: { title: '版权引进', icon: 'example' },
    alwaysShow: true,
    children: [
      {
        path: 'chapterlist',
        name: 'CopyRightInChapterList',
        component: () => import('@/views/copyrightin/chapter/chapterlist'),
        meta: { title: '章节列表', icon: 'table' }
      },
      {
        path: 'chapterupdate/:id', // ## :id 相当于占位符,要传参数
        name: 'CopyRightInChapterUpdate',
        component: () => import('@/views/copyrightin/chapter/chapterupdate'),
        meta: { title: '编辑章节', noCache: true },
        hidden: true
      }
    ]
  },
  {
    path: '/bms/copyright',
    component: Layout,
    redirect: '/bms/copyright',
    name: 'Copyright',
    meta: { title: '版权引进', icon: 'example' },
    alwaysShow: true,
    children: [
      {
        path: 'list',
        name: 'CopyrightinBatch',
        component: () => import('@/views/copyrightin/batch/list'),
        meta: { title: '批次管理', icon: 'table' }
      },
      {
        path: 'create',
        name: 'CopyrightinBatchCreate',
        component: () => import('@/views/copyrightin/batch/create'),
        meta: { title: '添加批次', icon: 'form' },
        hidden: true
      },
      {
        path: 'update/:id', // ## :id 相当于占位符,要传参数
        name: 'CopyrightinBatchUpdate',
        component: () => import('@/views/copyrightin/batch/update'),
        meta: { title: '修改批次', noCache: true },
        hidden: true
      }
    ]
  },
  {
    path: '/copyrightin',
    component: Layout,
    redirect: '/bms/copyright',
    name: 'Copyright',
    meta: { title: '版权引进', icon: 'example' },
    alwaysShow: true,
    children: [
      {
        path: 'list',
        name: 'BmsBookList',
        component: () => import('@/views/bms/copyright/bookList/list'),
        meta: {title: '书单管理', icon: 'table'}
      },
      {
        path: 'create',
        name: 'BmsBookListCreate',
        component: () => import('@/views/bms/copyright/bookList/create'),
        meta: { title: '添加书单', icon: 'form'},
        hidden: true
      },
      {
        path: 'update/:id',
        name: 'BmsBookListUpdate',
        component: () => import('@/views/bms/copyright/bookList/update'),
        meta: { title: '修改书单', icon: 'true'},
        hidden: true
      },
    ]
  },
  {
    path: '/bms/copyrightout/batch',
    component: Layout,
    redirect: '/bms/copyrightout/batch',
    name: 'Copyrightout',
    meta: { title: '版权输出', icon: 'example'},
    alwaysShow: true,
    children: [
      {
        path: 'list',
        name: 'BmsBookList',
        component: () => import('@/views/bms/copyrightout/batch/list'),
        meta: { title: '批次管理', icon: 'table'}
      },
      {
        path: 'create',
        name: 'BmsBookListCreate',
        component: () => import('@/views/bms/copyrightout/batch/create'),
        meta: { title: '添加批次', icon: 'form'},
        hidden: true
      },
      {
        path: 'update/:id',
        name: 'BmsBookListUpdate',
        component: () => import('@/views/bms/copyrightout/batch/update'),
        meta: { title: '修改批次', icon: 'true'},
        hidden: true
      },
    ]
  },
  {
    path: '/copyrightout/operator',
    component: Layout,
    redirect: '/copyrightout/operator',
    name: 'Operator',
    meta: { title: '运营方管理', icon: 'example' },
    alwaysShow: true,
    children: [
      {
        path: 'list',
        name: 'CopyrightOutOperatorList',
        component: () => import('@/views/copyrightout/operator/list'),
        meta: { title: '运营方列表', icon: 'table' }
      },
      {
        path: 'create',
        name: 'CopyrightOutOperatorCreate',
        component: () => import('@/views/copyrightout/operator/create'),
        meta: { title: '运营方添加', icon: 'tree' },
        hidden: true
      },
      {
        path: 'update/:id',
        name: 'CopyrightOutOperatorUpdate',
        component: () => import('@/views/copyrightout/operator/update'),
        meta: { title: '运营方修改', icon: 'tree' },
        hidden: true
      }
    ]
  }, {
    path: '/copyrightout/linkman',
    component: Layout,
    redirect: '/copyrightout/linkman',
    name: 'Linkman',
    meta: { title: '联系人管理', icon: 'example' },
    alwaysShow: true,
    hidden: true,
    children: [
      {
        path: 'list/:id',
        name: 'CopyrightOutLinkmanList',
        component: () => import('@/views/copyrightout/linkman/list'),
        meta: { title: '联系人列表', icon: 'table' }
      },
      {
        path: 'create/:id',
        name: 'CopyrightOutLinkmanCreate',
        component: () => import('@/views/copyrightout/linkman/create'),
        meta: { title: '联系人添加', icon: 'tree' },
        hidden: true
      },
      {
        path: 'update/:page/:id',
        name: 'CopyrightOutLinkmanUpdate',
        component: () => import('@/views/copyrightout/linkman/update'),
        meta: { title: '联系人修改', icon: 'tree' },
        hidden: true
      }
    ]
  },
  {
    path: '/copyrightout/settlement',
    component: Layout,
    redirect: '/copyrightout/settlement',
    name: 'Settlement',
    meta: { title: '结算管理', icon: 'example' },
    alwaysShow: true,
    hidden: true,
    children: [
      {
        path: 'list/:id',
        name: 'CopyrightOutSettlementList',
        component: () => import('@/views/copyrightout/settlement/list'),
        meta: { title: '结算管理列表', icon: 'table' }
      },
      {
        path: 'create/:id',
        name: 'CopyrightOutSettlementCreate',
        component: () => import('@/views/copyrightout/settlement/create'),
        meta: { title: '结算管理添加', icon: 'tree' },
        hidden: true
      },
      {
        path: 'update/:page/:id',
        name: 'CopyrightOutSettlementUpdate',
        component: () => import('@/views/copyrightout/settlement/update'),
        meta: { title: '结算管理修改', icon: 'tree' },
        hidden: true
      }
    ]
  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
